package com.zjl.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.zjl.entity.HotelEntity;
import com.zjl.util.DBManager;
import com.zjl.util.QueryResult;


public class HotelDaoImpl {
	
	public ArrayList<HotelEntity> selectAll(String hotel) {
		ArrayList<HotelEntity> alist= new ArrayList<HotelEntity>();
	    String sqlString;
	    if (hotel!=null&&hotel.equals("")) {
	    	sqlString="select hotel_id,hotel,hotel_type,price,discount_price,hotel_state,remark from hotel where hotel like '%"+hotel+"%'";
		}else {
			sqlString="select hotel_id,hotel,hotel_type,price,discount_price,hotel_state,remark from hotel";
		}
	    QueryResult rSet=DBManager.executeQuery(sqlString);
	      if (rSet!=null) {
	        try {
	          while (rSet.rs.next()) {
	            alist.add(new HotelEntity(rSet.rs.getInt("hotel_id"),
	            		rSet.rs.getString("hotel"),
	            		rSet.rs.getString("hotel_type"),
	            		rSet.rs.getString("price"),
	            		rSet.rs.getString("discount_price"),rSet.rs.getString("hotel_state"),
	            		rSet.rs.getString("remark")));
	          }
	        } catch (SQLException e) {
	          e.printStackTrace();
	        }
	      }
	      rSet.close();
	    return alist;
	}
	
	public HotelEntity userDetail(int id) {
		HotelEntity userBean= null;
		String sqlString="select hotel_id,hotel,hotel_type,price,discount_price,hotel_state,remark from hotel where hotel_id='"+id+"'";
		QueryResult rSet=DBManager.executeQuery(sqlString);
			if (rSet!=null) {
				try {
					ResultSet rsSet=rSet.rs;
					while (rsSet.next()) {
						userBean=new HotelEntity(rSet.rs.getInt("hotel_id"),
								rSet.rs.getString("hotel"),
			            		rSet.rs.getString("hotel_type"),
			            		rSet.rs.getString("price"),
			            		rSet.rs.getString("discount_price"),rSet.rs.getString("hotel_state"),
			            		rSet.rs.getString("remark"));
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			rSet.close();
			return userBean;
	}
}
